package com.lzx.spark.sanbao.tcsl.utils;

import org.apache.spark.SparkConf;
import org.apache.spark.sql.SparkSession;

/**
 * @author lzx
 * @version 1.0
 * @date 2024/8/24 下午4:41
 * @description: TODO
 */
public class sparkEnv {
    public static SparkConf buildSparkConf() {
        return (new SparkConf()).setAppName("sparksql").setMaster("local[*]");
    }

    public static SparkSession buildSparkSessionForTesting() {
        SparkConf conf = buildSparkConf();
        return SparkSession.builder()
                .config(conf)
                .config("spark.driver.bindAddress", "127.0.0.1")
                .config("spark.executor.memory", "4g")
                .config("spark.driver.memory", "8g")
                .config("spark.dynamicAllocation.enabled", "true")
                .config("spark.dynamicAllocation.shuffleTracking.enabled", "true")
                .config("spark.dynamicAllocation.shuffleTracking.timeout", "120s")
                .config("spark.dynamicAllocation.minExecutors", "6")
                .config("spark.dynamicAllocation.maxExecutors", "10")
                .config("spark.dynamicAllocation.initialExecutors", "6")
                .config("spark.kubernetes.allocation.batch.size", "1")
                .config("spark.dynamicAllocation.executorAllocationRatio", "1")
                .config("spark.dynamicAllocation.schedulerBacklogTimeout", "1s")
                .config("spark.dynamicAllocation.executorIdleTimeout", "120s")
                .config("spark.kubernetes.executor.deleteOnTermination", "true")
                .config("spark.decommission.enabled", "true")
                .config("spark.storage.decommission.enabled", "true")
                .config("spark.storage.decommission.rddBlocks.enabled", "true")
                .config("spark.storage.decommission.shuffleBlocks.enabled", "true")
                .config("spark.sql.autoBroadcastJoinThreshold", "-1")
                .config("spark.sql.catalogImplementation", "hive")
                .enableHiveSupport()
                .getOrCreate();
    }
}
